<style type="text/css">
#add_blog_image_box
{
    background-color: #FFF;
    border: 2px solid #666;
    padding: 5px;
    width: 300px;
    height: 90px;
    position: absolute;
    left: 490px;
    top: 420px;
    display: none;
}
</style>
<div class="form">

<?php $form=$this->beginWidget('CActiveForm', array(
	'id'=>'blog-form',
	'enableAjaxValidation'=>false,
        'htmlOptions' => array('enctype' => 'multipart/form-data'),
)); ?>

	<p class="note">Fields with <span class="required">*</span> are required.</p>

	<?php echo $form->errorSummary($model); ?>

	<div class="row">
		<?php echo $form->labelEx($model,'title'); ?>
		<?php echo $form->textField($model,'title',array('size'=>60,'maxlength'=>255)); ?>
		<?php echo $form->error($model,'title'); ?>
	</div>

	<div class="row">
		<?php echo $form->labelEx($model,'discription'); ?>
            <?php
            echo $form->textArea($model,'discription',array('rows'=>10, 'cols'=>80));
            /*
            $this->widget('ext.ckeditor.CKEditorWidget',array(
  "model"=>$model,                 # Data-Model
  "attribute"=>'discription',          # Attribute in the Data-Model
  "defaultValue"=>$model->discription,     # Optional

  # Additional Parameter (Check http://docs.cksource.com/ckeditor_api/symbols/CKEDITOR.config.html)
  "config" => array(
      "height"=>"400px",
      "width"=>"100%",
      "toolbar"=>"Full",
      ),

  #Optional address settings if you did not copy ckeditor on application root
  "ckEditor"=>Yii::app()->basePath."/../ckeditor/ckeditor.php",
                                  # Path to ckeditor.php
  "ckBasePath"=>Yii::app()->baseUrl."/ckeditor/",
                                  # Realtive Path to the Editor (from Web-Root)
  ) );
             *
             */
            ?>
		<?php //echo $form->textArea($model,'discription',array('rows'=>6, 'cols'=>50)); ?>
		<?php echo $form->error($model,'discription'); ?>
            
	</div>

	<div class="row">
<?php
if($model->thumbnail != null){
    $thumb_array = explode(',', $model->thumbnail);
}  else {
    $thumb_array = array();
}
$rawData = array();
foreach($thumb_array as $key=>$value){
    $rawData[] = array('id'=>$model->id,'thumb'=>Tool::get_thumb($value),'image'=>$value);
}
$blog_images=new CArrayDataProvider($rawData, array(
    'pagination'=>array(
        'pageSize'=>10,
    ),
));
echo $form->labelEx($model,'thumbnail');
echo CHtml::link('Add Image','javascript:;',array('id'=>'add_blog_image_btn'));

$this->widget('zii.widgets.grid.CGridView', array(
    'id'=>'blog-image-grid',
    'dataProvider'=> $blog_images,
    //'filter'=>  ProjectImage::model(),
    'summaryText'=> '',
    'selectableRows' => false,
    'hideHeader'=> true,
    'filterPosition'=>'footer',
    //'hasFooter'=> false,
    'columns'=>array(
        //'id',
        array('name'=>'image','type' => 'raw','value'=>'CHtml::image(Yii::app()->baseUrl."/".$data["thumb"],$data["thumb"],array("width"=>"70","height"=>"60"))'),
        array(
            'class'=>'CButtonColumn',
            'template'=>'{delete}',
//            'viewButtonUrl'=>'Yii::app()->createUrl("/projectImage/view", array("id" => $data["id"]))',
//            'viewButtonLabel'=> '',
//            'viewButtonImageUrl'=> '',
//            'updateButtonImageUrl'=> '',
//            'updateButtonLabel'=> '',
            'deleteButtonUrl'=>'Yii::app()->createUrl("/blog/removeImage", array("image" => $data["image"],"blog" => $data["id"]))',
        ),
    ),
)); 
?>
</div>
	<div class="row">
            <?php
                $category_array = CHtml::listData(BlogCategory::model()->findAll(), "id", "name");
                ?>
                <?php echo $form->labelEx($model,'category'); ?>
                <?php echo $form->listBox($model,'category',$category_array); ?>
                <?php echo $form->error($model,'category'); ?>
	</div>
	<div class="row">
		<?php echo $form->labelEx($model,'tag'); ?>
		<?php echo $form->textField($model,'tag',array('size'=>60,'maxlength'=>255)); ?>
		<?php echo $form->error($model,'tag'); ?>
	</div>
	<div class="row">
                <?php
                $artist_array = CHtml::listData(Artist::model()->findAll(), "id", "name");
                array_unshift($artist_array,"No Artist");
                ?>
                <?php echo $form->labelEx($model,'artist'); ?>
                <?php 
                //echo $form->listBox($model,'artist',$artist_array,array('multiple'=>'multiple')); 
                echo $form->listBox($model,'artist',$artist_array); 
                ?>
                <?php echo $form->error($model,'artist'); ?>
	</div>
    <div class="row">
            <?php
                $home_array = CHtml::listData(Home::model()->findAll(), "id", "name");
                ?>
                <?php echo $form->labelEx($model,'home_show'); ?>
                <?php echo $form->checkBox($model,'home_show'); ?>
                <?php echo $form->error($model,'home_show'); ?>
	</div>
        <div class="row">
                <?php echo $form->labelEx($model,'recommend'); ?>
                <?php echo $form->checkBox($model,'recommend'); ?>
                <?php echo $form->error($model,'recommend'); ?>
	</div>
	<div class="row buttons">
		<?php echo CHtml::submitButton($model->isNewRecord ? 'Create' : 'Save'); ?>
	</div>

<?php $this->endWidget(); 
echo '<div id="add_blog_image_box">';
$image_model = new BlogThumbForm;
$image_model->blog = $model->id;
echo $this->renderPartial('/blog/_image_form', array('model'=> $image_model));
echo '</div>';
?>

</div><!-- form -->
<script type="text/javascript">
$(function(){
    $('#add_blog_image_btn').click(
        function(){
            $('#add_blog_image_box').show();
        }
    );
    $('#close_blog_image_box_btn').click(
        function(){
            $('#add_blog_image_box').hide();
        }
    );
});
</script>